package com.cugmarket.controller.comment;

import com.cugmarket.dto.CommentCreateDTO;
import com.cugmarket.dto.CommentPageDTO;
import com.cugmarket.dto.Result;
import com.cugmarket.entity.Comment;
import com.cugmarket.service.CommentService;
import com.cugmarket.vo.CommentVO;
import com.cugmarket.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    // 获取指定商品的评论列表，按照两层结构返回 CommentVO
    @GetMapping("/{productId}")
    public Result<List<CommentVO>> getComments(@PathVariable String productId) {
        List<CommentVO> comments = commentService.getComments(productId);
        return Result.success(comments);
    }

    // 发布评论或回复
    @PostMapping("/add")
    public Result<Void> addComment(@RequestBody Comment comment) {
        commentService.addComment(comment);
        return Result.success();
    }

    /**
     * 获取指定产品的分页评论
     * @param commentPageDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageVO> getCommentsByPage(@RequestBody CommentPageDTO commentPageDTO) {
        PageVO pageVO = commentService.getCommentsByPage(commentPageDTO);
        return Result.success(pageVO);
    }



}
